package UserService.controller;


import UserService.config.config_refresh;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import UserService.IService.IUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.User;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Api(tags="用户接口")
@RestController
@RequestMapping(value="/user")
@RequiredArgsConstructor
//@RefreshScope //自动热更新配置
public class UserController {

    private final IUserService userService;

//    @Value("${pattern.dateformat}")
//    private String dateformat;

    @Autowired
    private config_refresh refresh;

    @ApiOperation("ID查询用户")
    @GetMapping("/{userid}")
    @ResponseBody
    public User getUser(@ApiParam("用户ID") @PathVariable int userid) {
        return userService.getById(userid);
    }

    @GetMapping("/now")
    @ResponseBody
    public String now() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(refresh.getDateformat()));
    }
}
